//
//  UIWindow+Extension.m
//  小和微博
//
//  Created by 董晓合 on 15/3/2.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "UIWindow+Extension.h"
#import "CZNewfeatureViewController.h"
#import "CZWelcomeViewController.h"


@implementation UIWindow (Extension)

- (void)chooseRootViewController {

    //        3.判断是否显示新特性
    //        3.1 获取当前版本号
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    //        3.2 获取从沙河中获取的版本号
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *sandboxVersion = [defaults objectForKey:@"CFBundleShortVersionString"];
    //        3.3 比较两个版本号
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if ([currentVersion compare:sandboxVersion] == NSOrderedDescending) {
        //        新特性
        CZNewfeatureViewController *newfeatureVc = [[CZNewfeatureViewController alloc] init];
        window.rootViewController = newfeatureVc;
        //            存储当前版本号
        [defaults setObject:currentVersion forKey:@"CFBundleShortVersionString"];
        [defaults synchronize];
    } else {
        //        欢迎界面 
        CZWelcomeViewController *welcomeVc = [[CZWelcomeViewController alloc] init];
        window.rootViewController = welcomeVc;
        
    }

}

@end
